package cn.lrl.consumeropenfeign80.controller;

import cn.lrl.api.generation.pojo.User;
import cn.lrl.api.clients.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/consumer")
@Slf4j
public class UserClientController {

    @Autowired
    UserClient userClient;

    /**
     * 消费方添加部门信息
     */
    @RequestMapping(value = "/user/add", method = RequestMethod.POST)
    public boolean add(User user) {
        return userClient.addDept(user);
    }

    /**
     * 消费方根据id查询部门信息
     */
    @RequestMapping(value = "/user/get/{id}", method = RequestMethod.GET)
    public User get(@PathVariable("id") Long id) {
        log.info("消费端接口暴露成功，获取前端id：" + id);
        return userClient.queryById(id);
    }

    /**
     * 消费方查询部门信息列表
     */
    @RequestMapping(value = "/user/list", method = RequestMethod.GET)
    public List<User> list() {
        return userClient.queryAll();
    }
}
